package cn.codergege.demo.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.Date;
import java.util.Map;

@Controller
@PropertySource("classpath:/application.properties")
public class IndexController {
    private final Logger log = LoggerFactory.getLogger(IndexController.class);

    @Autowired
    private Environment env;

    @RequestMapping(value = { "/", "/index", "/home" }, method = RequestMethod.GET)
    public String index(Map map) {
        Date date = new Date();
        map.put("date", date);
        map.put("author", env.getProperty("author"));

        log.info("HomeController runs, date: " + date);

        return "index";
    }

    @RequestMapping("/homepage")
    public String homePage() {
        return "redirect:/index";
    }
}

			